import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/models/categroyModel.dart';
import 'package:flutter_shop/provider/category.dart';
import 'package:provider/provider.dart';

class CategoryLeftMenu extends StatefulWidget {
  @override
  _CategoryLeftMenuState createState() {
    return _CategoryLeftMenuState();
  }
}

class _CategoryLeftMenuState extends State<CategoryLeftMenu> {
  List<CategoryBigModel> list = [];
  int index = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }

  Widget _leftInkWell(CategoryProvider categoryProvider, int index) {
    return InkWell(
      onTap: () {
        this.index = index;
        categoryProvider.setChildCategory(this.list[index].bxMallSubDto);
      },
      child: Container(
        height: ScreenUtil().setHeight(100.0),
        padding: EdgeInsets.only(left: 10.0, top: 20.0),
        decoration: BoxDecoration(
            color: this.index == index ? Colors.black12 : Colors.white,
            border: index != (this.list.length - 1)
                ? Border(bottom: BorderSide(width: 1.0, color: Colors.black12))
                : null),
        child: Text(
          this.list[index].mallCategoryName,
          style: TextStyle(fontSize: ScreenUtil().setSp(28.0)),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Consumer<CategoryProvider>(
      builder: (context, category, _) {
        this.list = category.leftMenuList;
        return Container(
          width: ScreenUtil().setWidth(180.0),
          decoration: BoxDecoration(
              border:
                  Border(right: BorderSide(width: 1.0, color: Colors.black12))),
          child: ListView.builder(
            scrollDirection: Axis.vertical,
            itemCount: category.leftMenuList.length,
            itemBuilder: (context, index) {
              return this._leftInkWell(category, index);
            },
          ),
        );
      },
    );
  }
}
